<template>
    <el-dialog
            :visible.sync="dialogVisible"
            width="400px"
            :before-close="closeDialog"
            append-to-body
            title="修改字典"
    >
    
    
        <el-form  :label-position="labelPosition"  label-width="70px" ref="form" :model="form"  v-loading="loading">
            
             <el-form-item prop="code" label="字典编码">
                <el-input size= "small" type="text" placeholder="请输入字典编码"  v-model="form.code"></el-input>
            </el-form-item>

             <el-form-item prop="value" label="字典名称">
                <el-input size= "small" type="text"  placeholder="请输入字典名称"  v-model="form.value"></el-input>
            </el-form-item>

             <el-form-item prop="order" label="排序">
                <el-input size= "small" type="text"  placeholder="请输入排序"  v-model="form.order"></el-input>
            </el-form-item>
            
             <el-form-item prop="ext" label="扩展数据">
                <el-input size= "small" type="textarea" placeholder="请输入扩展数据"  v-model="form.ext"></el-input>
            </el-form-item>

             <el-form-item prop="remark" label="备注">
                <el-input size= "small" type="textarea"  v-model="form.remark"></el-input>
            </el-form-item>
        </el-form>
        <div class="btn-group">
            <el-button type="text" size="small" plain @click="closeDialog">取消</el-button>
            <el-button type="primary"  size="small" :disabled="loading" @click="submit">确定</el-button>
        </div>
        
    </el-dialog>
    
</template>

<script>

    import {updateDic} from '@/api/dic'
    export default {
        data(){
            return {
                labelPosition:'right',
                dialogVisible: false,
                loading: false,
                form: {
                    parentCode:"",
                    code:"",
                    value:"",
                    order:"",
                    ext:"",
                    remark:""
                },
            }
        },
        created(){
           
        },
        methods:{
            showDialog(row){
                this.form = row;
                this.dialogVisible = true
            },
            closeDialog(){
                this.form = {};
                this.dialogVisible = false
                this.loading = false
            },
            submit(){
                this.$refs.form.validate(async valid => {
                    if(valid){
                        try{
                            this.loading = true
                            let res = await updateDic(this.form);
                            if(res.status == '200'){
                                this.$message.success('修改成功')
                                this.closeDialog()
                                this.$emit('success')
                            }else{
                                this.$message.error(res.msg)
                                this.loading = false
                            }
                        }catch{
                            this.loading = false
                        }
                    }
                });
            }
        }
    }
</script>
<style lang="scss" scoped>
    .btn-group{
        display: flex;
        justify-content: right;
        .el-button{
            width: 50px;
        }
    }
    .el-form-item{
        height: 40px;
    }
</style>